<template>
  <el-select style="width: 100%" v-model="name" clearable filterable placeholder="请选择所属账户"
             @change="selectCompany" value-key="id">
    <el-option
      v-for="item in companyList"
      :key="item.id"
      :label="item.name"
      :value="item">
    </el-option>
  </el-select>
</template>

<script>
import {list} from '@/api/company'
import utils from '../../utils/utils.js'
export default{
  // props:["operatorName"],
  data(){
    return{
      query:{
        companyId:''
      },
      companyList:[],
      companyName:''
    }
  },
  props:{
    queryTitle:{
      type:String,
      value:'请选择所属账户'
    },
    name:{
      type:String,
      value:''
    }
  },
  watch:{
    name(newval,oldval){
      this.shopName=newval
    }

  },
  created() {
    this.companyName=this.name
    this.loadCompany()
  },
  methods:{
    selectCompany(data) {
      console.log(data)
      if(!utils.isNull(data)){
        this.query.companyId = data.id
        this.query.name = data.name
      }else{
        this.query.companyId = ''
        this.query.name = ''
      }
      this.$emit('queryCompanyClick',this.query)
    },
    loadCompany() {
      var _this = this
      let params = new URLSearchParams();
      list(params).then(response => {
        console.log(response);
        _this.companyList = response.data.data
      }).catch(error => {
        console.log('error!!')
      });
    }
  }
}
</script>

<style>
</style>

